package com.sky.controller.admin;

import com.sky.dto.ExecutionDTO;
import com.sky.dto.ExecutionPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.ExecutionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/execution")
@Api(tags = "执法相关接口")
@Slf4j
public class ExecutionController {
    @Autowired
    private ExecutionService executionService;

    /**
     * 分页查询
     * @param pageQuery
     * @return
     */
    @RequiresPermissions("管理员")
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(ExecutionPageQueryDTO pageQuery) {
        PageResult pageResult = executionService.pageQuery(pageQuery);
        return Result.success(pageResult);
    }

    /**
     * 执法记录修改
     * @param executionDTO
     * @return
     */
    @RequiresPermissions("管理员")
    @PutMapping("/update")
    @ApiOperation(value = "修改执法记录")
    public Result update(@RequestBody ExecutionDTO executionDTO) {
        executionService.update(executionDTO);
        return Result.success();
    }

    /**
     * 执法记录删除
     * @param ids
     * @return
     */
    @RequiresPermissions("管理员")
    @DeleteMapping
    @ApiOperation(value = "删除执法记录")
    public Result deleteBatch(@RequestParam List<Long> ids) {
        executionService.deleteBatch(ids);
        return Result.success();
    }
    /**
     * 执法记录添加
     * @param executionDTO
     * @return
     */
    @RequiresPermissions("管理员")
    @PostMapping()
    @ApiOperation(value = "添加执法记录")
    public Result add(ExecutionDTO executionDTO) {
        executionService.add(executionDTO);
        return Result.success();
    }

}
